var windowName = "siteArrange";
apiready = function(){
    onWindowShow(function () {
        log("show")
        var cur = getLocData("curSite")
        Page.curSite = cur;
        getData(Page)
    })
    onWindowHide(function () {
    })
    console.log("index page is OK");
    var Page = createVM("#Page",{
        //页面数据
        curSite:{},
        curStep:0,
        zbdw:["张三","李四"],
        value1:"",
        fanglan: {
            "2": "放缆队长张三"
        },
        rongjie: {
            "3": "熔接队长李四"
        },
        ziguan: {
            "4": "办公室王五",
            "5": "资源管理陈六"
        }
        ,en:{}
    },{
        //页面方法
        init:function () {
            // var cur = getLocData("curSite")
            // this.curSite = getLocData("curSite");
            // getData(this)
        }
        ,setCur:function (index) {
            this.curStep = index
        }

        ,submit:function() {
            var _this = this
            this.en.sid = this.curSite.id
            this.$refs.form.validate().then((result) => {
                logJson(result)
                if (result){
                    var form = createForm(this.en);
                    // var en = this.en
                    // logJson(en)
                    // for(var i in en){
                    //     form["form[" + i +"]"] = en[i]
                    // }
                    // logJson(form)
                    form["sid"] = this.en.sid
                    apiPost("/app/site/arrange",form,function (res) {
                        log(res)
                        showToast(res.message)
                    })

                }else{
                    showToast("请检查输入")
                }
            });
        },
    })

    Page.init()

}

function getData(_this) {
    var sid = _this.curSite.id
    // log(sid)
    apiLoad("/app/site/arrange",{sid:sid},function (res) {
        _this.fanglan = res.data.fanglan
        _this.rongjie = res.data.rongjie
        _this.ziguan = res.data.ziguan
        _this.en = res.data.en
        log(res)
    })
}